package com.wuxiaofan.secondkill.service;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wuxiaofan.secondkill.client.Idgenerator;
import com.wuxiaofan.secondkill.entity.SeckillOrder;
import com.wuxiaofan.secondkill.entity.custom.SeckillOrderCustom;
import com.wuxiaofan.secondkill.mapper.SeckillOrderMapper;
import javax.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SeckillOrderService {
    @Autowired
    private SeckillOrderMapper SeckillOrderMapper;
    @Resource
    private Idgenerator idgenerator;

    public SeckillOrder findById(String id){
        return SeckillOrderMapper.selectById(id);
    }

    public SeckillOrderCustom findCountByMap(Map paraMap){
        return SeckillOrderMapper.findCountByMap(paraMap);
    }

    public SeckillOrderCustom findGroupByMap(Map paraMap){
        return SeckillOrderMapper.findGroupByMap(paraMap);
    }

    public List<SeckillOrderCustom> findByMap(Map paraMap){
        return SeckillOrderMapper.findByMap(paraMap);
    }

    public Page<SeckillOrderCustom> findByMap(Map paraMap, Page page){
        return page.setRecords(SeckillOrderMapper.findByMap(paraMap,page));
    }


    public void updateMapById(Map paraMap){
        SeckillOrderMapper.updateMapById(paraMap);
    }
    public void delById(String id){
        SeckillOrderMapper.deleteById(id);
    }

    public SeckillOrder save(SeckillOrder SeckillOrder){
        SeckillOrder.setId(idgenerator.getId());
        SeckillOrderMapper.insert(SeckillOrder);
        return SeckillOrder;
    }

}
